package com.fqy.gmall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fqy.gmall.common.result.Result;
import com.fqy.gmall.model.product.BaseTrademark;
import com.fqy.gmall.product.service.BaseTrademarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * User: fqy
 * Date: 2021/9/10
 * Time: 22:42
 * Describe:
 */
@Api(tags = "品牌列表:品牌列表接口")
@RequestMapping("admin/product/baseTrademark/")
@RestController
public class BaseTradeMarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;
    //admin/product/baseTrademark/{page}/{limit}
    //获取品牌分页列表
    @ApiOperation("获取品牌分页列表")
    @GetMapping("{page}/{limit}")
    public Result getTradeMarkPage(
            @PathVariable Long page,
            @PathVariable Long limit
    ){
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        //  调用方法：
        IPage iPage = baseTrademarkService.getTradeMarkPage(baseTrademarkPage);
        return Result.ok(iPage);
    }
    //品牌列表:添加保存品牌
    @ApiOperation("添加保存品牌")
    @PostMapping("save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    //品牌列表:删除品牌
    @ApiOperation("删除保存品牌")
    @DeleteMapping("remove/{id}")
    public Result updateBaseTrademark(@PathVariable Long id){
        baseTrademarkService.remove(new QueryWrapper<BaseTrademark>().eq("id",id));
        return Result.ok();
    }
    //品牌列表:修改品牌 根据Id 获取数据！
    @ApiOperation("根据Id获取数据")
    @GetMapping("get/{id}")
    public Result getBaseTrademarkById(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }
    //品牌列表:修改品牌 更新更改的数据
    @ApiOperation("修改保存品牌")
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        //  调用方法 ：
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

}
